package com.easy.admin.system.test.netty;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.ServerSocketChannel;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;


/**
 *
 *
 * @author wangbo
 * @deprecated netty server
 */

public class NettyServer {
    public static void main(String[] args) throws Exception {
        //1.创建线程池，用来建立连接
        EventLoopGroup pGroup = new NioEventLoopGroup();
        //2.创建线程池用来处理消息
        EventLoopGroup wGroup = new NioEventLoopGroup();

        //3.创建启动器
        ServerBootstrap bootstrap = new ServerBootstrap();
        bootstrap.group(pGroup, wGroup)
                .channel(NioServerSocketChannel.class)
                .option(ChannelOption.SO_BACKLOG, 1024)//用来存放三次握手机制的队列长度
                .childOption(ChannelOption.SO_KEEPALIVE, true)//心跳保护机制
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    protected void initChannel(SocketChannel socketChannel) throws Exception {
                        socketChannel.pipeline().addLast(new NettyServerHandler());
                    }
                });
        Channel channel = bootstrap.bind(9090).sync().channel();
        channel.closeFuture().sync();
        pGroup.shutdownGracefully();
        wGroup.shutdownGracefully();

    }
}
